﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using DataAccess;
using DataAccess.ArchivesTableAdapters;
using System.Data;

namespace BusinessLogic
{
    [DataObject]
    public class DocumentBO
    {
        private tblDocumentsTableAdapter DocumentAdapter = null;
        protected tblDocumentsTableAdapter Adapter
        {
            get
            {
                if (DocumentAdapter == null)
                    DocumentAdapter = new tblDocumentsTableAdapter();
                return DocumentAdapter;
            }
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public Archives.tblDocumentsDataTable GetAllDocuments()
        {
            return Adapter.GetAllDocuments();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public DataTable GetByID(int docID)
        {
            return Adapter.GetByID(docID);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetByDocCode(string docCode, string depCode)
        {
            return Adapter.GetByDocCodeUser(docCode, depCode);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetByDocCode(string docCode)
        {
            return Adapter.GetByDocCode(docCode);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetByFromDate(string fromDate, string toDate)
        {

            return Adapter.GetFromDate(DateTime.Parse(fromDate), DateTime.Parse(toDate));
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetByFromDate(string fromDate, string toDate, string depCode)
        {

            return Adapter.GetByDateUser(DateTime.Parse(fromDate), DateTime.Parse(toDate), depCode);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetBySender(string senderID)
        {

            return Adapter.GetBySender(Convert.ToInt32(senderID));
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetBySender(string senderID, string depCode)
        {

            return Adapter.GetBySenderUser(Convert.ToInt32(senderID), depCode);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetByDocType(string dtID)
        {

            return Adapter.GetByDocType(Convert.ToInt32(dtID));
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetByDocType(string dtID, string depCode)
        {

            return Adapter.GetByDocTypeUser(Convert.ToInt32(dtID), depCode);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetByRecipient(string recipientID)
        {

            return Adapter.GetByRecipient(Convert.ToInt32(recipientID));
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetByStatus(string status)
        {

            return Adapter.GetByStatus(Convert.ToBoolean(status));
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetApprovedDocByRecipient(int depID)
        {

            return Adapter.GetApprovedDocByRecipient(depID);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Archives.tblDocumentsDataTable GetAllPendingDocuments()
        {
            return Adapter.GetAllPendingDocuments();
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public DataTable SearchAllDocuments(string docCode, string fromDate, string toDate, string sender, string receiver, bool? inOut, bool? status)
        {
            //return Adapter.SearchAllDocuments(docCode, fromDate, toDate, sender, receiver, inOut, status);
            return Adapter.SearchAllDocuments(null, null, null, sender, null, null, null);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
        public int Update(int docNumber, int dtID, int docSender, DateTime dateOfReceipt, string shortenedDetail, string storePath, bool status, int docID)
        {
            return Adapter.UpdateDocument(docNumber, dtID, docSender, dateOfReceipt,shortenedDetail, storePath, status, docID);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
        public int ApproveDoc(bool status, int docID)
        {
            return Adapter.ApproveDoc(status, docID);
        }
        [DataObjectMethodAttribute(DataObjectMethodType.Update, false)]
        public int UpdateAdopter(int adopterID, int docID)
        {
            return Adapter.UpdateAdopter(adopterID, docID);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
        public int Delete(int docID)
        {
            Adapter.DeleteAllRecipients(docID);
            return Adapter.Delete1(docID);
        }

        [DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
        public int AddNewDocument(int docNumber, int dtID, int docSender, DateTime dateOfReceipt, int adoptedBy, bool inOut, string shortenedDetail, string storePath)
        {
            return Adapter.AddNewDocument(docNumber, dtID, docSender, dateOfReceipt.ToShortDateString(), adoptedBy, inOut, shortenedDetail, storePath);
        }
    }
}
